package com.corpcredit.webapp.action;

import java.io.Serializable;

import com.corpcredit.model.Jbqk;
import com.corpcredit.model.Ykfcpjxs;
import com.corpcredit.webapp.action.BasePage;
import com.corpcredit.service.GenericManager;

public class YkfcpjxsForm extends BasePage implements Serializable {
    private GenericManager<Ykfcpjxs, Long> ykfcpjxsManager;
    private Ykfcpjxs ykfcpjxs = new Ykfcpjxs();
    private Long id;
    private Jbqk jbqk;

    public void setJbqk( Jbqk jbqk )
    {
        this.jbqk = jbqk;
    }
    public void setYkfcpjxsManager(GenericManager<Ykfcpjxs, Long> ykfcpjxsManager) {
        this.ykfcpjxsManager = ykfcpjxsManager;
    }

    public Ykfcpjxs getYkfcpjxs() {
        return ykfcpjxs;
    }

    public void setYkfcpjxs(Ykfcpjxs ykfcpjxs) {
        this.ykfcpjxs = ykfcpjxs;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        ykfcpjxsManager.remove(ykfcpjxs.getId());
        addMessage("ykfcpjxs.deleted");

        return "list";
    }

    public String edit() {
        // Comparison to zero (vs. null) is required with MyFaces 1.2.2, not with previous versions
        if (id != null && id != 0) {
            ykfcpjxs = ykfcpjxsManager.get(id);
        } else {
            ykfcpjxs = new Ykfcpjxs();
        }

        return "edit";
    }

    public String save() {
        boolean isNew = (ykfcpjxs.getId() == null || ykfcpjxs.getId() == 0);
        // set the related jbqk as a foreign key.
        ykfcpjxs.setJbqk( jbqk );
        ykfcpjxsManager.save(ykfcpjxs);

        String key = (isNew) ? "ykfcpjxs.added" : "ykfcpjxs.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
            return "edit";
        }
    }
} 